A task that is commonly performed in computer systems is conversion of often large sets of data from one encoding system to another. Many different encoding approaches are known, but determining a optimal approach for encoding and decoding data in particular systems and situations is an often challenging task. Translating from a one code to a different code in most computer systems is a processor-intensive task.
One oft-used encoding scheme is base64, which is specified for use with email attachments, including files of many different types, such as images, sound, video, executable, document files, etc. The use of email with attachments is wide-spread—trillions of data bytes are base64 encoded and decoded each day, consuming vast quantities of CPU resources. Each email attachment generally consists of one or more base64 encoded segments.
Furthermore, typically, when a web browser client requests an image from a webserver, the webserver may find the image, base64 encode the image, and then sends the base64 encoded image data to the browser client. The browser then receives the base64 encoded image, decodes it, and displays it in the browser's window.
Thus, Base64 encoding and decoding is a method that allows binary data to be transported from one place to another by first converting the binary data to “human readable text” and then sending the data. On the receiving side the “human readable text” is converted back into the original binary data. Base64 encoding and decoding is specified by an international standard whenever emails contain attachments. For example, see the discussion at http(://)email(.)about(.) com/cs/standards/a/mime.htm.
The table below (adapted from Wikipedia) shows how three binary bytes are encoded into four base64 digits in one example encoding scheme. Note that any arbitrary bit stream can be encoded 24 bits at a time into Base64, but for this example, is shown three byte values (24 bits) of “M”, “a”, and “n” for simplicity. However, the “M,” “a” and “n” are more correctly and generally understood as standing for their corresponding 8-bit patterns as shown, since Base64 encoding is often used for non-text attachments, such as images.

Traditional base64 encode/decode methods use a series of bit-shifts and bit masks to both encode and decode. Some methods use small “helper” tables, but still have to bit-shift and bitmask. While the above table makes the task appear straight forward, in practice it is not. Bit-shifting and bit-masking is required because while the Base-64 encoded data is logically encoded into 6-bit values, those values are converted into 8-bit values in order to be handled by standard digital processing and transmission.